<template>
  <el-dialog :title="title" width="50%" :visible.sync="visible">
    <el-form v-if="form!=null" ref="form" class="dialog-form" :model="form" label-position="right" label-width="120px">
      <el-form-item label="地点">
        <label>{{ form.name }}</label>
      </el-form-item>
      <el-form-item label="联系人" prop="linkman" :rules="self.page.rules.def">
        <el-input v-model="form.linkman" class="col-3" />
      </el-form-item>
      <el-form-item label="联系方式" prop="mobile" :rules="self.page.rules.phone">
        <el-input v-model="form.mobile" class="col-3" />
      </el-form-item>
      <el-form-item label="地区" prop="areaIds" :rules="self.page.rules.def">
        <form-area v-model="form.areaIds" class="col-3" :area="form.area" :level="3" @set-area="setArea" />
      </el-form-item>
      <el-form-item label="详细地址" prop="address" :rules="self.page.rules.def">
        <el-input v-model="form.address" class="col-12" placeholder="请输入详细地址" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取 消</el-button>
      <el-button size="mini" type="primary" @click="submit">提交</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  name: 'EditLocation',
  props: {
    self: {
      type: Object,
      default: () => { return {} }
    }
  },
  data() {
    return {
      visible: false,
      form: null,
      title: ''
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    show(_form, title) {
      this.title = title
      this.form = _form
      this.visible = true
    },
    submit() {
      const that = this

      that.$refs['form'].validate((valid) => {
        if (!valid) {
          return
        }
        const loading = that.$loading()
        const url = that.self.page.router.remoteUrl + '/update-location'
        that.self.service.post(url, that.form).then(res => {
          loading.close()
          if (res.code !== 200) {
            that.$message.error(res.message)
            return
          }
          that.$message.success('操作成功!')
          that.visible = false
          that.self.reload(true)
        }).catch((e) => {
          loading.close()
        })
      })
    },
    setArea(val) {
      // alert(val);
      this.form.area = val
    }
  }
}
</script>
